import request from 'utils/request'

/**
 * 获取文章列表
 * @param {*} params {status, channel_id, begin_pubdate, end_pubdate, page, per_page}
 * @returns promise
 */
// export const getArticles = (params = {}) => {
//   return request({
//     method: 'GET',
//     url: '/mp/articles',
//     params,
//   })
// }
export const getArticles = (params = {}) =>
  request.get('/mp/articles', { params })

/**
 * 删除文章
 * @param {*} id 文章id
 * @returns promise
 */
export const removeArticles = (id) => {
  return request({
    method: 'DELETE',
    url: '/mp/articles/' + id,
  })
}

/**
 * 发表文章
 * @param {*} data 主体内容，文章发表内容
 * @param {*} draft 是否为草稿
 * @returns promise
 */
export const addArticles = (data, draft = false) => {
  return request({
    method: 'POST',
    url: '/mp/articles',
    params: {
      draft,
    },
    data,
  })
}

/**
 * 根据 id 获取文章详情
 * @param {*} id 文章id
 * @returns promise
 */
export const getArticleById = (id) => {
  return request({
    method: 'GET',
    url: `/mp/articles/${id}`,
  })
}

/**
 * 根据 id 修改文章详情
 * @param {*} id 文章id
 * @param {*} data 文章主体内容
 * @param {*} draft 是否为草稿
 * @returns promise
 */
export const editArticleById = (id, data, draft = false) => {
  return request({
    method: 'PUT',
    url: `/mp/articles/${id}`,
    params: {
      draft,
    },
    data,
  })
}
